package data;

import java.util.List;

import models.Attendant;

import org.sql2o.Sql2o;

public class ReportDAO implements IReportDAO {
	private static Sql2o database;
	static {
		database = new Connection().open();
	}
	
	public List<Attendant> listAttendants(int studentId){
		final String sql = "select a.id, s.name as 'sessionName', c.name as 'courseName', a.status from Attendant a join TeachingSession s on a.sessionId = s.id join Course c on c.id = a.courseId where studentId = :studentId Order by a.courseId";
		return database.createQuery(sql).addParameter("studentId", studentId).executeAndFetch(Attendant.class);
	}
	
	public List<Attendant> listCourseAttendants(int courseId) {
		final String sql = "select a.id, s.name as 'sessionName', c.name as 'courseName', a.status from Attendant a join TeachingSession s on a.sessionId = s.id join Course c on c.id = a.courseId where a.courseId = :courseId";
		return database.createQuery(sql).addParameter("courseId", courseId).executeAndFetch(Attendant.class);
	}
}
